from conans import ConanFile, CMake, tools
from conans import tools


class TestConan(ConanFile):
    name = "user_test"
    version = "1.0"
    license = "<Put the package license here>"
    author = "<Put your name here> <And your email here>"
    url = "<Package recipe repository url here, for issues about the package>"
    description = "<Description of Test here>"
    topics = ("<Put some tag here>", "<here>", "<and here>")
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False]}
    default_options = {"shared": False}
    generators = "cmake_find_package"

    def source(self):
        print("call test")

    def build(self):
        print("call test")
        print(self.env_info)
        self.run("gcc -v")
        print(self.cpp_info)
        print("path " + self.source_folder + " is where the package built")
        print("build env is ",tools.get_env("BUILD_ENV"))
        tools.rmdir(tools.unix_path(self.package_folder)+"/build")
        tools.mkdir(tools.unix_path(self.package_folder)+"/build")
        if tools.os_info.is_windows:
            print("current os windows")
            if tools.os_info.is_cygwin:
                print("cygwin build")
            if tools.get_env("BUILD_ENV")=="msys":
                print("msys build")
                tools.run_in_windows_bash(self, subsystem="msys",cwd="",msys_mingw=True,bashcmd="ls -l") 
                tools.run_in_windows_bash(self, subsystem="msys",cwd="",msys_mingw=True,bashcmd="cmake build -G\"MinGW Makefiles\" . " ) 
                #tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake --build . ") 

    def package(self):
        self.copy("*.so", dst="lib", keep_path=False)
        self.copy("*.dylib", dst="lib", keep_path=False)
        self.copy("*.a", dst="lib", keep_path=False)

    def requirements(self):
        self.requires("test/1.1.1")
        self.requires("libuv/1.x")

    def export(self):
        self.copy("CMakeLists.txt")

